package com.mg.flightplan.domain;

import java.util.ArrayList;
import java.util.List;

public abstract class FlightPlan {

	protected String flightPlanName;
	protected List<ICAOWaypoint> icaoList = new ArrayList<ICAOWaypoint>();
	int index = 0;
	
	public FlightPlan() {
		super();
	}

	public int getWptCount(){
		return (icaoList.size()>=1)?icaoList.size()-1:0;
	}

	public int getCurrWptNumber(){
		return index;
	}
	
	public ICAOWaypoint getPreviousWpt(){
		if (index>0 && index < icaoList.size())
			return icaoList.get(index-1);
		else
			return null;
	}
	
	public ICAOWaypoint getCurrentWpt(){
		if (index < icaoList.size())
			return icaoList.get(index);
		else
			return null;
	}
	
	public ICAOWaypoint getNextWpt(){
		if ((index+1) < icaoList.size())
			return icaoList.get(index+1);
		else
			return null;
	}
	
	public ICAOWaypoint getLastWpt(){
		return icaoList.get(icaoList.size()-1);
	}
	
	public void moveNextWpt(){
		index ++;
	}
	
	/**
	 * @return Distance from the wpt <i>we just passed over</i> until the end
	 */
	public int getDistanceLeftToArrival(){
		int distanceLeft=0;
		for (int i = index;i<icaoList.size();i++){
			ICAOWaypoint wpt=icaoList.get(i);
			distanceLeft +=wpt.distFromPrevious;
		}
		return distanceLeft;
	}
	
}